package com.modernyuanshiren.sample;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import com.modernyuanshiren.AbstractStatus;
import com.modernyuanshiren.IAction;
import com.modernyuanshiren.IElement;

public class SampleStatus extends
		AbstractStatus<SampleStatus, SampleSingleAction> {

	@Override
	public boolean isEnd() {
		String leftName = Game.getGameContext().getLeftName();
		String rightName = Game.getGameContext().getRightName();
		boolean left = IntStream.range(0, 3).allMatch(
				i -> is(getElementByPosition(i), rightName));
		boolean right = IntStream.range(4, 7).allMatch(
				i -> is(getElementByPosition(i), leftName));
		return left && right;
	}

	@Override
	protected List<List<IElement>> getAllElementCombinations() {
		String emptyName = Game.getGameContext().getEmptyName();
		IElement emptyElement = this.getElementByName(emptyName).get(0);
		return getAllElements().stream().filter(e -> !e.is(emptyName))
				.map(e -> Arrays.asList(e, emptyElement))
				.collect(Collectors.toList());
	}

	@Override
	protected List<SampleSingleAction> getAllSingleActions() {
		return Arrays.asList(SampleSingleAction.values());
	}

	@Override
	protected IAction<SampleStatus, SampleSingleAction> createAction(
			List<IElement> elements, SampleSingleAction singleAction) {
		return new SampleAction(elements, singleAction);
	}
}
